package baidu.hudson.plugin.result.collector.utils;

import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.type.TypeFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;

/**
 * Created by IntelliJ IDEA.
 * User: Richard
 * Date: 4/17/11
 * Time: 11:40 PM
 * To change this template use File | Settings | File Templates.
 */
public class JsonUtils {
    private static ObjectMapper mapper = new ObjectMapper();
    private JsonUtils(){

    }
    public static String convertMapToJson(Map<String,Object> map){

        String value="";
        try {
            value = getMapper().writeValueAsString(map);
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        java.util.zip.ZipEntry zipEntry = new ZipEntry("");
        return value;
    }



    public static List<String> convertJsonListString(String listString) throws IOException {
       List<String> numberList = new ArrayList<String>();
        numberList = getMapper().readValue(listString, TypeFactory.collectionType(List.class, String.class));
       return numberList;
    }


    public static ObjectMapper getMapper() {
        return mapper;
    }

    public static void setMapper(ObjectMapper mapper) {
        JsonUtils.mapper = mapper;
    }
}
